package com.lianzhihui.minitiktok.ui

import androidx.fragment.app.Fragment
import com.chaychan.library.BottomBarItem
import com.chaychan.library.BottomBarLayout
import com.lianzhihui.onlyleague.R
import com.lianzhihui.minitiktok.adapter.MyFragmentAdapter
import com.lianzhihui.minitiktok.ui.main.HomeFourFragment
import com.lianzhihui.minitiktok.ui.main.HomeOneFragment
import com.lianzhihui.minitiktok.ui.main.HomeThreeFragment
import com.lianzhihui.minitiktok.ui.main.HomeTwoFragment
import com.echofeng.common.ui.base.BaseActivity
import com.echofeng.common.utils.MyToast
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : BaseActivity(), BottomBarLayout.OnItemSelectedListener {
    companion object {
        var curMainPage = 0
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_main;
    }

    override fun initView() {
        val fragmentList = ArrayList<Fragment>()
        fragmentList.add(HomeOneFragment())
        fragmentList.add(HomeTwoFragment())
        fragmentList.add(HomeThreeFragment())
        fragmentList.add(HomeFourFragment())
        val fragmentManager = supportFragmentManager
        val adapter = MyFragmentAdapter(fragmentManager, fragmentList)
        mViewPager.setAdapter(adapter)
        mViewPager.setScrollable(false)
        mViewPager.setOffscreenPageLimit(4)
        mBottomBarLayout.setOnItemSelectedListener(this)
    }

    override fun onItemSelected(p0: BottomBarItem?, p1: Int, p2: Int) {
        when(p2){
            0,1 ->{
                mViewPager.setCurrentItem(p2, false)
            }
            2 ->{
                MyToast.showToast("暂未开放")
            }
            3,4->{
                mViewPager.setCurrentItem(p2-1, false)
            }
        }
    }

}